setwd("/home1/30/jc227089/SRE_inv/PBS")

sp<-1:50

script.file<-'/home1/30/jc227089/evo-dispersal/SRE_inv/SRE_inv_runs.R'

for (ii in 1:length(sp)) {
	fid<-ii
	##create the sh file
	zz = file(paste("SREinv", fid,'.sh',sep=''),'w')
	cat('##################################\n',file=zz)
	cat('#!/bin/sh\n',file=zz)
	cat('cd $PBS_O_WORKDIR\n',file=zz)
	cat("R CMD BATCH --no-save --no-restore '--args rr=50 file.ID=",fid, " sp=", sp[ii], "' ", sep="", file=zz)
	cat(script.file, " ", paste("SREinv", fid,'.Rout',sep=''), "\n", sep="",file=zz)
	cat('##################################\n',file=zz)
	close(zz)
			
	#submit the job
	system(paste("qsub -m n ", paste("SREinv", fid,".sh",sep=""),sep=""))
}
